package com.googlecode.boliang.q07;

public class ReverseWords {

	public String doReverse(StringBuffer sb) {
		String reverseStr = sb.reverse().toString();
		String[] strArray = reverseStr.split(" "); 
		String resultStr = null; 
		for (int i = 0; i < strArray.length; i++) {
			StringBuffer strb = new StringBuffer(); 
			strb.append(strArray[i]); 
			strArray[i] = strb.reverse().toString();
			
			if (resultStr == null) {
				resultStr = strArray[i] + " "; 
			} else if (i == strArray.length - 1) {
				resultStr = resultStr + strArray[i]; 
			} else {
				resultStr = resultStr + strArray[i] + " ";				
			}

			
		}
		return resultStr;
	}
}
